package com.example.myapplication.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsonUtil {

    //jackson 包 要引入
//    private static ObjectMapper objectMapper;
    private static ObjectMapper objectMapper = new ObjectMapper();
//
    public static String getJson(Object object) throws JsonProcessingException {
        return objectMapper.writeValueAsString(object);
    }
    public static HashMap getMap(String json) throws JsonProcessingException {

        return  objectMapper.readValue(json, HashMap.class);
    }
    public static List<Map> getListMap(String json) throws JsonProcessingException {
        return  objectMapper.readValue(json, new TypeReference<ArrayList<Map>>() {});
    }

}
